#!/bin/zsh
# @Time  :2022-05-15 16:06:24
# @Author:selfeasy
# @Email :selfeasy@qq.com
# Script Description: 字典的使用

declare -A ipaddress #定义一个字典名称(关联数组)

#赋值
ipaddress=([master1]="10.1.90.181" [master2]="10.1.90.182" [master3]="10.1.90.183" [node1]="10.1.90.184")

#获取key值
echo ${!ipaddress[*]}

#获取value值
echo ${ipaddress[*]}

#获取指定key对应的value值
echo ${ipaddress[master1]}

declare -A maps 

maps=([no1]='1,2,3,4') #字典的value是列表

for i in ${maps[no1]};do
    echo $i
done

declare -A meshs

# 'appid password port'
meshs=([0]='hello,89d05661e6b5b,37001')
meshs+=([1]='hello1,89d05661e6b,37002')
for mesh in ${ipaddress[*]};do
    arr=(${mesh//,/ })
    echo ${arr[0]}
    echo ${arr[2]}